package co.yixiang.hw.rest;

import co.yixiang.annotation.AnonymousAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Walert
 */
@Api(tags = "微信公众号业务控制类")
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/wx/portal/business")
public class WxPortalApiController {
    private final WxMpService wxService;
//    private final WxMpMessageRouter messageRouter;


    @ApiOperation(value = "根据Code获取用户信息")
    @GetMapping(value = "/userByCode/{code}")
    @AnonymousAccess
    public Object CodeByUserInfo(@PathVariable("code") String code) throws WxErrorException {
        return wxService.oauth2getUserInfo(wxService.oauth2getAccessToken(code),null);
    }

}
